package com.shxc.smarttrade.old.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.bean.FollowDivideListInfo;
import com.shxc.smarttrade.old.myinterface.PositionItemClickListener;
import com.shxc.smarttrade.old.myview.CustomTextView;
import com.shxc.smarttrade.old.utils.BaseUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jcdev1 on 2017/5/10.
 */

public class FollowDivideListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    LayoutInflater mInflater;
    Context mContext;
    List<FollowDivideListInfo.DataBean.SettlesBean> traderOrderList;
    private PositionItemClickListener listener;

    public FollowDivideListAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setDatas(List<FollowDivideListInfo.DataBean.SettlesBean> traderOrderList) {
        this.traderOrderList = traderOrderList;
        notifyDataSetChanged();
    }

    public void setOnPositionItemClickListener(PositionItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AllPositionViewholder(mInflater.inflate(R.layout.adapter_follow_order_detail, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        if (holder instanceof AllPositionViewholder) {
            FollowDivideListInfo.DataBean.SettlesBean sb = traderOrderList.get(position);
            Glide.with(mContext).load(sb.getHeaderLink()).into(((AllPositionViewholder) holder).ivHead);
            ((AllPositionViewholder) holder).tvName.setText(sb.getUserName());
            if (sb.getCopyProfit() < 0) {
                ((AllPositionViewholder) holder).tvProfit.setTextColor(mContext.getResources().getColor(R.color.stock_fell_color));
                ((AllPositionViewholder) holder).tvProfit.setText("-$" + BaseUtils.getDigitsData(Math.abs(sb.getCopyProfit()), 2));

            } else {
                ((AllPositionViewholder) holder).tvProfit.setTextColor(mContext.getResources().getColor(R.color.stock_rise_color));
                ((AllPositionViewholder) holder).tvProfit.setText("$" + BaseUtils.getDigitsData(sb.getCopyProfit(), 2));
            }
            ((AllPositionViewholder) holder).tvDivide.setText("$" + BaseUtils.getDigitsData(sb.getPayProfit(), 2));
            ((AllPositionViewholder) holder).tvTime.setText("结算日期：" + BaseUtils.getDateFromMillionSeconds(sb.getPayTime(), "yyyy-MM-dd"));

        }

    }

    @Override
    public int getItemCount() {
        return traderOrderList != null && traderOrderList.size() > 0 ? traderOrderList.size() : 0;
    }


    public class AllPositionViewholder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_head)
        ImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_time)
        CustomTextView tvTime;
        @BindView(R.id.tv_profit)
        TextView tvProfit;
        @BindView(R.id.tv_divide)
        TextView tvDivide;

        AllPositionViewholder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            AutoUtils.autoSize(view);
        }
    }

    public class FootViewHolder extends RecyclerView.ViewHolder {
        FootViewHolder(View view) {
            super(view);
        }
    }
}
